package com.jackrain.nea.fc.cp.mapper;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.jdbc.SQL;

/**
 * 职位级别
 * Mapper
 *
 * @author xuxinshuai
 * @create 2017/12/15
 */
@Mapper
public interface ViewCpostGradeMapper {


    /**
     * HR007_ID
     *
     * @param hr007id
     * @return String
     */
    @Select("SELECT count(1) FROM CP_C_POSTGRADE WHERE HR007_ID = #{hr007id}")
    Integer selectGradeCount(String hr007id);



    /***
     * 新增岗位级别
     * @param gradeObj
     * @return int
     */
    @UpdateProvider(type = ViewCpostGradeMapper.CpostgradeSqlProvider.class,
            method = "insertSql")
    int insertPostGrade(JSONObject gradeObj);
    /***
     * 更新岗位级别
     * @param gradeObj
     * @return int
     */
    @UpdateProvider(type = ViewCpostGradeMapper.CpostgradeSqlProvider.class,
            method = "updateSql")
    int updatePostGrade(JSONObject gradeObj);


    class CpostgradeSqlProvider {

        public String updateSql(JSONObject map) {
            return new SQL() {
                {
                    UPDATE("CP_C_POSTGRADE");
                    for (String key : map.keySet()) {
                        String id = "HR007_ID";
                        if (!id.equals(key)) {
                            SET(key + "= #{" + key + "}");
                        }
                    }
                    WHERE("HR007_ID = #{HR007_ID}");
                }

            }.toString();
        }

        public String insertSql(JSONObject jo) {
            return new SQL() {
                {
                    INSERT_INTO("CP_C_POSTGRADE");
                    for (String key : jo.keySet()) {
                        VALUES(key, "#{" + key + "}");
                    }
                }
            }.toString();
        }



    }

}
